package server

import (
	"github.com/cuiyuanxin/airuisi-admin/global"
	"github.com/cuiyuanxin/airuisi-admin/internal/repository"
	"github.com/cuiyuanxin/airuisi-admin/pkg/config"
	"github.com/cuiyuanxin/airuisi-admin/pkg/logger"
	"github.com/cuiyuanxin/airuisi-admin/pkg/tracer"
)

func setupSetting(configFile string) error {
	configs, err := config.NewSetting(configFile)
	if err == nil {
		global.Config = configs
	}
	return err
}

func setupLogger(configSetting *config.Configs) error {
	loger, err := logger.NewLogger(configSetting)
	if err == nil {
		global.Logger = loger
	}
	return err
}

func setupDBEngine(configSetting *config.Configs) error {
	db, err := repository.NewDBEngine(configSetting)
	if err == nil {
		global.Db = db
	}
	return err
}

func setupRDBClient(configSetting *config.Configs) error {
	rdb := repository.NewRDBClient(configSetting)
	global.Rdb = rdb

	return nil
}

func setupTracer(configSetting *config.Configs) error {
	jaegerTracer, _, err := tracer.NewJaegerTracer(configSetting.App.AppName+` service`, configSetting.Tracer.AgentHostPort)
	if err == nil {
		global.Tracet = jaegerTracer
	}

	return nil
}
